﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace eTMS.Controls
{

    public partial class ucCommandDialog : UserControl
    {
        public ucCommandDialog()
        {
            InitializeComponent();
        }
        public event CancelEventHandler OnOK;
        public event CancelEventHandler OnCancel;
        private void btnExit_Click(object sender, EventArgs e)
        {
            CancelEventArgs args = new CancelEventArgs();
            args.Cancel = false;
            if (OnCancel != null)
            {
                OnCancel(sender, args);
            }
            if (!args.Cancel)
            {
                this.ParentForm.DialogResult = DialogResult.Cancel;
                this.ParentForm.Close();
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            CancelEventArgs args = new CancelEventArgs();
            args.Cancel = false;
            if (OnOK != null)
            {
                OnOK(sender, args);
            }
            if (!args.Cancel)
            {
                this.ParentForm.DialogResult = DialogResult.OK;
                this.ParentForm.Close();
            }
        }
        private void ucCommandButton_Load(object sender, EventArgs e)
        {
            this.ParentForm.CancelButton = this.btnExit;
            this.DoubleBuffered = true;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            DrawBackGround(e.Graphics);

        }
        private Color endgradColor = Color.FromArgb(200, 220, 230);
        private Color startgradColor = Color.FromArgb(220, 230, 255);
        private LinearGradientMode gradientMode = LinearGradientMode.Vertical;
        private float gradPercent = 0.5f;
        public LinearGradientMode GradientMode
        {
            get
            {
                return gradientMode;
            }
            set
            {
                gradientMode = value;
                this.Invalidate();
            }
        }
        public float GradientPercent
        {
            get
            {
                return gradPercent;
            }
            set
            {
                gradPercent = value;
                this.Invalidate();
            }
        }
        public Color StartGradientColor
        {
            get
            {
                return startgradColor;
            }
            set
            {
                startgradColor = value;
                this.Invalidate();
            }
        }
        public Color EndGradientColor
        {
            get
            {
                return endgradColor;
            }
            set
            {
                endgradColor = value;
                this.Invalidate();
            }
        }

        private void DrawBackGround(Graphics g)
        {
            // Create a rectangle
            g.Clear(this.BackColor);
            Rectangle rect = this.ClientRectangle;
            // Create a linear gradient brush
            LinearGradientBrush rgBrush =
                new LinearGradientBrush(
                rect, this.startgradColor, this.endgradColor, gradientMode
            );					// Set signma bell shape
            rgBrush.SetSigmaBellShape(gradPercent, 1.0f);
            // Fill rectangle again
            g.FillRectangle(rgBrush, rect);
            rgBrush.Dispose();
        }

        public  void SetFocusOK()
        {
            btnOK.Focus();
        }
        public void RaiseOKClick()
        {
            btnOK.PerformClick();
        }
    }
}